package cn.javase.base.internet._01_网络编程基础类;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;

public class _基础类 {
    public static void main(String[] args) throws UnknownHostException, MalformedURLException {
        // 本机
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);
        System.out.println("本机主机名或域名为：" + localHost.getHostName());
        System.out.println("本机IP地址为：" + localHost.getHostAddress());
        // 百度
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress);
        System.out.println("远程主机名或域名为：" + inetAddress.getHostName());
        System.out.println("远程IP地址为：" + inetAddress.getHostAddress());
        System.out.println("================================================");
        URL url = new URL("http://127.0.0.1:8080/oa/index.html?name=zhangsan#tip");
        String protocol = url.getProtocol();
        System.out.println("协议：" + protocol);
        String host = url.getHost();
        System.out.println("主机地址：" + host);
        int port = url.getPort();
        System.out.println("端口：" + port);
        int defaultPort = url.getDefaultPort();
        System.out.println("默认端口：" + defaultPort);
        String ref = url.getRef();
        System.out.println("锚点：" + ref);
        String path = url.getPath();
        System.out.println("资源路径：" + path);
        String query = url.getQuery();
        System.out.println("查询参数：" + query);
        String file = url.getFile();
        System.out.println("资源路径 + 查询参数：" + file);
    }
}
